﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PMC.Urls.Default
{
    public partial class EmailFetcherSettingForm : Form
    {
        private bool _allowClosing;

        public String Username
        {
            get { return tbUsername.Text; }
            set { tbUsername.Text = value; }
        }

        public String Password
        {
            get { return tbPassword.Text; }
            set { tbPassword.Text = value; }
        }

        public int Port
        {
            get { return (int)upPort.Value; }
            set { upPort.Value = value; }
        }

        public String Host
        {
            get { return tbHost.Text; }
            set { tbHost.Text = value; }
        }

        public bool SSL
        {
            get { return cbSSL.Checked; }
            set { cbSSL.Checked = value; }
        }

        public EmailFetcherSettingForm(bool allowCancel)
        {
            _allowClosing = allowCancel;
            InitializeComponent();
            btCancel.Visible = allowCancel;
        }

        private void btSubmit_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(tbUsername.Text) || String.IsNullOrWhiteSpace(tbPassword.Text) || String.IsNullOrWhiteSpace(tbHost.Text))
            {
                MessageBox.Show(this, "Some fields may be empty, please check!", "Fields empty or whitespaced",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
                return;
            }
            _allowClosing = true;
        }

        private void Settings_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = !_allowClosing;
        }
    }
}
